home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / IPreferenceControl.m < prev    next >
Text File  |  1993-01-12  |  6KB  |  183 lines

  1. /*$Copyright:
  2.  * Copyright (C) 1992.5.22. Recruit Co.,Ltd. 
  3.  * Institute for Supercomputing Research
  4.  * All rights reserved.
  5.  * NewsBase  by ISR, Kazuto MIYAI, Gary ARAKAKI, Katsunori SUZUKI, Kok-meng Lue
  6.  *
  7.  * You may freely copy, distribute and reuse the code in this program under 
  8.  * following conditions.
  9.  * - to include this notice in the source code, if it is to be distributed 
  10.  *   with source code.
  11.  * - to add the file named "COPYING" within the code, which shall include 
  12.  *   GNU GENERAL PUBLIC LICENSE(*).
  13.  * - to display an acknowledgement in binary code as follows: "This product
  14.  *   includes software developed by Recruit Co.,Ltd., ISR."
  15.  * - to display a notice which shall state that the users may freely copy,
  16.  *   distribute and reuse the code in this program under GNU GENERAL PUBLIC
  17.  *   LICENSE(*)
  18.  * - to indicate the way to access the copy of GNU GENERAL PUBLIC LICENSE(*)
  19.  *
  20.  *   (*)GNU GENERAL PUBLIC LICENSE is stored in the file named COPYING
  21.  * 
  22.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  23.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  24.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  25. $*/
  26. /* IPreferenceControl.m */
  27.  
  28. #import "IPreferenceControl.h"
  29. #import <appkit/appkit.h>
  30. #import <defaults/defaults.h>
  31. #import <string.h>
  32. #import <libc.h>
  33. #import <objc/hashtable.h>
  34. #import "errdebug.h"
  35. #import "data_types.h"
  36. #import "Localization.h"
  37.  
  38. #define LoStr(key)      doLocalString(NULL,key,NULL)
  39.  
  40. @implementation IPreferenceControl
  41.  
  42. - init
  43. {
  44.     const char    *home_dir;
  45.     char    *newsrc_dir;
  46.     const char    *newsrc_file=".newsbaserc";
  47.     char    *get_mail_address();
  48.     
  49.     NXDefaultsVector NewsBaseDefaults = {
  50.     {NNTPSERVER, "localhost"},
  51.     {NEWSRCFILE, ""},
  52.     {ARTICLEBROWSERMODE, "Browser"},
  53.     {NEWSGROUPBROWSERMODE, "Browser"},
  54.     {ARTICLESELECT, SINGLECLICK},
  55.     {NUM_ARTTOGET, "20"},
  56.     {ARTICLESIZEMARK, "0:100:300"},
  57.     {RECONNECTTIME, "30"},
  58.         {KANJICODE, "JIS"},
  59.     {NNTPBROWSER_FRAME, "(128,373):(740,458):(737,76):(737,330):(290,330):(439,330)"},
  60.     {NULL}
  61.     };
  62.     
  63.     [super init];
  64.  
  65.     if(!(NXRegisterDefaults(OWNER, NewsBaseDefaults))) {
  66.     NXRunAlertPanel(LoStr("NewsBase"),LoStr("can't open default database")
  67.     ,LoStr("OK"),NULL,NULL);
  68.     }
  69.     
  70.     /* if value for NEWSRCFILE =="", $HOME/.newsbaserc is set */
  71.     if (!(strcmp(NXGetDefaultValue(OWNER, NEWSRCFILE),""))) {
  72.     home_dir = NXHomeDirectory();
  73.     newsrc_dir = (char *)NXZoneMalloc([self zone], 
  74.                     strlen(home_dir)+strlen(newsrc_file)+2);
  75.     strcpy (newsrc_dir, home_dir); 
  76.     strcat (newsrc_dir, "/"); 
  77.     strcat (newsrc_dir, newsrc_file);
  78.     NXSetDefault (OWNER, NEWSRCFILE, newsrc_dir);
  79.     }
  80.     return self;
  81. }
  82.  
  83. - windowDidBecomeKey:sender
  84. {
  85.     [self read:self];
  86.     return self;
  87. }
  88.  
  89. - write:sender
  90. {
  91.     const char    *newsrc_dir;
  92.     char    buf[64];
  93.     
  94.     /* check save and newsrc file directory */
  95.     newsrc_dir = [oNewsrcFile stringValue];
  96.     if (*newsrc_dir!='/') {
  97.     NXRunAlertPanel(LoStr("NewsBase"),
  98.     LoStr("please set absolute path name to directory"),
  99.     LoStr("OK"),NULL,NULL);
  100.     return NULL;
  101.     }
  102.     
  103.     /* write value to database in local disk */
  104.     NXWriteDefault(OWNER, NNTPSERVER, [oNntpServer stringValue]);
  105.     NXWriteDefault(OWNER, RECONNECTTIME, 
  106.                     [oReconnectTime stringValue]);
  107.     NXWriteDefault(OWNER, KANJICODE, [[oKanjiCode selectedCell] title]);
  108.     NXWriteDefault(OWNER, NEWSRCFILE, [oNewsrcFile stringValue]);
  109.     NXWriteDefault(OWNER, ARTICLESELECT, 
  110.                     [[oArticleSelect selectedCell] title]);
  111.     NXWriteDefault(OWNER, NUM_ARTTOGET, [oNumArticleToGet stringValue]);
  112.  
  113.     sprintf(buf,"0:%.10d:%.10d", [oBoundaryTwo intValue], 
  114.                             [oBoundaryThree intValue]);
  115.     NXWriteDefault(OWNER, ARTICLESIZEMARK, buf);
  116.     
  117.     return self;
  118. }
  119.  
  120. - read:sender
  121. {
  122.     int        boundaryTwo, boundaryThree;
  123.     const char    *buffer;
  124.     
  125.     [oNntpServer setStringValue:NXGetDefaultValue(OWNER, NNTPSERVER)];
  126.     [oNewsrcFile setStringValue:NXGetDefaultValue(OWNER,NEWSRCFILE)];
  127.     [self _selectCellMatrix:oArticleSelect
  128.                 title:NXGetDefaultValue(OWNER, ARTICLESELECT)];
  129.     [self _selectCellMatrix:oKanjiCode
  130.                 title:NXGetDefaultValue(OWNER, KANJICODE)];
  131.     [oNumArticleToGet setStringValue:NXGetDefaultValue(OWNER,NUM_ARTTOGET)];
  132.  
  133.     if ((buffer=NXGetDefaultValue(OWNER,ARTICLESIZEMARK)) != 0) {
  134.     sscanf(buffer, "0:%d:%d", &boundaryTwo, &boundaryThree);
  135.     }
  136.     [oBoundaryTwo setIntValue:boundaryTwo];
  137.     [oBoundaryThree setIntValue:boundaryThree];
  138.     [oReconnectTime setStringValue:NXGetDefaultValue(OWNER,RECONNECTTIME)];
  139.     return(self);
  140. }
  141.  
  142. - (void)_selectCellMatrix:matrix title:(const char *)ktitle
  143. {
  144.     int        i;
  145.     id        cell;
  146.     
  147.     if (ktitle == NULL) {
  148.         [matrix selectCellAt:0 :0];
  149.         return;
  150.     }
  151.     for (i=0; i<[matrix cellCount]; i++) {
  152.     cell = [matrix cellAt:0 :i];
  153.     if(!(strcmp([cell title], ktitle))) {
  154.         [matrix selectCell:cell];
  155.         break;
  156.     }
  157.     }
  158. }
  159.  
  160. //- (char *)getMailAddress
  161. //{
  162. //    char    *mail_address;
  163. //    char    *user_name, machine_name[256], domain_name[257];
  164. //
  165. //    user_name = NXCopyStringBufferFromZone(getenv("USER"),[self zone]);
  166. //    gethostname(machine_name,sizeof(machine_name));
  167. //    getdomainname(domain_name + 1, sizeof(domain_name) - 1);
  168. //    domain_name[sizeof(domain_name) - 1] = '\0';
  169. //    if (domain_name[1] != '\0') {
  170. //        domain_name[0] = '.';
  171. //    } else {
  172. //        domain_name[0] = '\0';
  173. //    }
  174. //    mail_address = (char *)NXZoneMalloc([self zone],
  175. //        strlen(user_name)+strlen(machine_name)+strlen(domain_name)+3);
  176. //    (void)sprintf(mail_address,"%s@%s%s",user_name,machine_name,
  177. //                                domain_name);
  178. //    return mail_address;
  179. //}
  180. //
  181. //
  182. @end
  183.